{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 第1周作业\n",
    "\n",
    "1. Linux 发行版本：CentOS, RedHat，Ubuntu等\n",
    "\n",
    "2. 实现一个简易的计算器，效果如下：\n",
    "   运行后提示让用户输入一个数字\n",
    "   1. 提示输入操作符（+ - * /）\n",
    "   2. 再次提示输入一个数字\n",
    "   3. 打印计算结果\n",
    "   4. 在不退出程序的前提下，可以允许用户继续输入新一组数据计算"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.3 + 1.2 = 2.5\n"
     ]
    }
   ],
   "source": [
    "# 计算器：\n",
    "\n",
    "while True:\n",
    "\n",
    "    \n",
    "\n",
    "    n1 = input(\"请输入一个数字：\")\n",
    "    if n1 == \"\": break\n",
    "    operator = input(\"请输入一个操作符(+ - * /)：\")\n",
    "    if  operator == \"\": break\n",
    "    n2 = input(\"请输入另一个数字：\")\n",
    "    if n2 == \"\": break\n",
    "\n",
    "    if operator == \"+\":\n",
    "        result = float(n1) + float(n2)\n",
    "    elif operator == \"-\":\n",
    "        result = float(n1) - float(n2)\n",
    "    elif operator == \"*\":\n",
    "        result = float(n1) * float(n2)\n",
    "    elif operator == \"/\" and n2 != \"0\":\n",
    "        result = float(n1) / float(n2)\n",
    "    else:\n",
    "        print(\"输入错误，请重新输入\")\n",
    "        continue\n",
    "\n",
    "    print(\"{} {} {} = {}\".format(n1,operator,n2,result))\n",
    "\n",
    "    \n",
    "\n",
    "\n",
    "    "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.5"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
